<?php

use yii\db\Migration;

/**
 * Class m171206_064245_createTableCourseSelect
 */
class m171206_064245_createTableCourseSelect extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%course_select}}', [

            'id' => $this->primaryKey()->comment('选课序号'),
            'user_id' => $this->integer()->notNull()->defaultValue(0)->comment('用户ID'),
            'course_id' => $this->string(50)->notNull()->defaultValue('')->comment('课程ID'),

            'status' => $this->smallInteger()->notNull()->defaultValue(10)->comment('状态'),
            'created_at' => $this->integer()->notNull()->defaultValue(0)->comment('创建时间'),
            'updated_at' => $this->integer()->notNull()->defaultValue(0)->comment('更新时间'),
        ], $tableOptions);

        $this->addCommentOnTable('{{%course_select}}','用户选课表');

        $this->createIndex('course_select_course_user_id','{{%course_select}}',['course_id','user_id']);
    }

    /**
     * @inheritdoc
     */
    public function safeDown()
    {
        $this->dropTable('{{%course_select}}');
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m171206_064245_createTableCourseSelect cannot be reverted.\n";

        return false;
    }
    */
}
